// @Name    : cai_base_http_proxy_config
// @author  : simon
// @date    : 2024/11/4 10:43

import 'package:shared_preferences/shared_preferences.dart';

class CaiBaseHttpProxyConfig {
  //设置是否使用小工具;不用小工具的情况下，要关闭代理工具开关；
  static Future<void> setUseTool(bool isUse) async {
    if (!isUse) {
      await CaiBaseHttpProxyConfig.setProxySwitch(false);
    }
  }

  //设置是否打开开关;不用小工具的情况下，要默认改为关闭；
  static Future<void> setProxySwitch(bool isOpen) async {
    final prefs = await SharedPreferences.getInstance();
    prefs.setBool('http_proxySwitch', isOpen);
  }

  //获取开关打开状态
  static Future<bool> getProxySwitch() async {
    final prefs = await SharedPreferences.getInstance();
    final value = prefs.getBool('http_proxySwitch');
    return value ?? false;
  }

  //设置代理ip
  static Future<bool> setProxyIp(String proxyIp) async {
    final prefs = await SharedPreferences.getInstance();
    final value = prefs.setString('http_proxyIp', proxyIp);
    return value;
  }

  static Future<String?> getProxyIp() async {
    final prefs = await SharedPreferences.getInstance();
    final value = prefs.getString('http_proxyIp');
    return value;
  }

  //设置代理终端号
  static Future<bool> setProxyPort(String proxyPort) async {
    final prefs = await SharedPreferences.getInstance();
    final value = prefs.setString('http_proxyPort', proxyPort);
    return value;
  }

  static Future<String?> getProxyPort() async {
    final prefs = await SharedPreferences.getInstance();
    final value = prefs.getString('http_proxyPort');
    return value;
  }

  ///移除配置数据
  static Future<bool> removeProxyConfig() async {
    final prefs = await SharedPreferences.getInstance();
    final value1 = prefs.remove('http_proxySwitch');
    // prefs.remove('http_proxyIp');
    // prefs.remove('http_proxyPort');
    return value1;
  }
}
